home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-10-06 | 11.2 KB | 367 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // BlitPixieInterface.h
- //
- // Provides a SpriteWorld interface into the BlitPixie routines.
- ///--------------------------------------------------------------------------------------
-
- #ifndef __BLITPIXIEINTERFACE__
- #define __BLITPIXIEINTERFACE__
-
- #ifndef __SWCOMMON__
- #include <SWCommonHeaders.h>
- #endif
-
-
- ///--------------------------------------------------------------------------------------
- // type definitions
- ///--------------------------------------------------------------------------------------
-
- typedef struct StarArray
- {
- short horizLoc; // Current horizontal position of the star
- short vertLoc; // Current vertical position of the star
- short oldHorizLoc; // Horizontal position of star the previous frame
- short oldVertLoc; // Vertical position of star the previous frame
- short horizSpeed; // To be used by the user to move the star
- short vertSpeed; // To be used by the user to move the star
- unsigned long color; // Current color of the star
- Boolean isOn; // Draw this star ?
- Boolean needsToBeErased; // If drawn last frame, then it needs to be erased.
- short userData; // Reserved for user
- } StarArray, *StarArrayPtr;
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=packed
- #endif
-
- struct RLEPixelData // 'RLE#' resource
- {
- unsigned short width; // pixel width (max for all frames)
- unsigned short height; // pixel height (max for all frames)
- unsigned short depth; // bit depth (8/16/32)
- unsigned short palette; // color table 'clut' ID (0 for default)
-
- unsigned short frames; // number of frames in this resource
- unsigned short reserved1;
- unsigned short reserved2;
- unsigned short reserved3;
-
- unsigned char tokens[1]; // the RLE token data (variable size array)
- };
-
- typedef struct RLEPixelData RLEPixelData,*RLEPixelDataPtr,**RLEPixelDataHdl;
-
- #define kRLEResourceType 'RLE#'
- #define kRLEResourceHeaderSize (sizeof(RLEPixelData) - sizeof(unsigned char))
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- ///--------------------------------------------------------------------------------------
- // Function prototypes for the DrawProcs that work in 8-bit, 16-bit, and 32-bit
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieClearDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixiePartialMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC Boolean BlitPixieMaskCollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieMaskColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
-
- SW_FUNC void BlitPixieRLEDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC Boolean BlitPixieRLECollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieRLEColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
-
- SW_FUNC void BlitPixieFlipRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieFlipMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC Boolean BlitPixieFlipMaskCollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect);
-
- SW_FUNC void BlitPixieFlipMaskColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect);
-
- ///--------------------------------------------------------------------------------------
- // Function prototypes for compiled sprite DrawProcs (68k only)
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieCompiledSpriteDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect);
-
- ///--------------------------------------------------------------------------------------
- // Function prototypes for the all-bit DrawProcs (68k only)
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieAllBitRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect);
-
- SW_FUNC void BlitPixieAllBitMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect);
-
- SW_FUNC void BlitPixieAllBitPartialMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect);
-
- ///--------------------------------------------------------------------------------------
- // Function prototype for the double-rect DrawProc (works in 8-bit, 16-bit, and 32-bit)
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieDoubleRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRectA,
- Rect* dstRectA,
- Rect* srcRectB,
- Rect* dstRectB);
-
- ///--------------------------------------------------------------------------------------
- // Function prototypes for misc stuff (GetPixel, SetPixel, star field stuff, etc.)
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC unsigned long SWGetValueFromColor(
- FramePtr dstFrameP,
- RGBColor *color);
-
- SW_FUNC void SWGetColorFromValue(
- FramePtr dstFrameP,
- RGBColor *color,
- unsigned long pixelValue);
-
- SW_FUNC void SWSetPixel(
- FramePtr dstFrameP,
- short x,
- short y,
- unsigned long color);
-
- SW_FUNC unsigned long SWGetPixel(
- FramePtr dstFrameP,
- short x,
- short y );
-
- SW_FUNC void SWAnimateStarField(
- SpriteWorldPtr spriteWorldP,
- StarArray *starArray,
- short numStars,
- unsigned long backColor);
-
-
- //------------------------------------------------------------------------------------------------
- // Pixel pointer macros
- ///-----------------------------------------------------------------------------------------------
-
- long SW_ROWBYTES(FramePtr frame, int rows); // rows to bytes
- long SW_PIXELBYTES(FramePtr frame, int pixels); // pixels to bytes
- Ptr SW_PIXELPTR(FramePtr frame, int x, int y); // get pointer to a pixel
-
- // special cases of SW_PIXELPTR:
- UInt8 *SW_PIXELPTR8(FramePtr frame, int x, int y); // get pointer to a 8-bit pixel
- UInt16 *SW_PIXELPTR16(FramePtr frame, int x, int y); // get pointer to a 16-bit pixel
- UInt32 *SW_PIXELPTR32(FramePtr frame, int x, int y); // get pointer to a 32-bit pixel
-
-
- /* SW_ASSERT( rows >= (frame)->frameRect.top && rows < (frame)->frameRect.bottom ) */
- #define SW_ROWBYTES(frame,rows) ( (frame)->scanLinePtrArray[ (rows) - (frame)->frameRect.top ] )
- //#define SW_ROWBYTES(frame,rows) ( (rows) * (frame)->frameRowBytes ) // <-- unoptimized
-
- /* SW_ASSERT( pixels >= (frame)->frameRect.left && pixels < (frame)->frameRect.right ) */
- #define SW_PIXELBYTES(frame,pixels) ( (pixels) << (frame)->pixelShift )
- //#define SW_PIXELBYTES(frame,pixels) ( ((pixels) * (frame)->frameDepth) >> 3 ) // <-- unoptimized
-
- /* SW_ASSERT( x >= (frame)->frameRect.left && x < (frame)->frameRect.right )
- SW_ASSERT( y >= (frame)->frameRect.top && y < (frame)->frameRect.bottom ) */
- #define SW_PIXELPTR(frame,x,y) \
- ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + SW_PIXELBYTES(frame,x) )
-
-
- #define SW_PIXELPTR8(frame,x,y) \
- ((UInt8 *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + (x) ))
-
- #define SW_PIXELPTR16(frame,x,y) \
- ((UInt16 *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + ((x)+(x)) ))
-
- #define SW_PIXELPTR32(frame,x,y) \
- ((UInt32 *) ( (frame)->frameBaseAddr + SW_ROWBYTES(frame,y) + ((x)<< 2) ))
-
-
- //------------------------------------------------------------------------------------------------
- // Bit-fiddling macros, avoiding conditionals and tables
- ///-----------------------------------------------------------------------------------------------
-
- void SW_BITSET(Ptr byteptr, int bitnum); // set a bit (1)
- void SW_BITCLR(Ptr byteptr, int bitnum); // clear a bit (0)
- Boolean SW_BITTST(Ptr byteptr, int bitnum); // test a bit
-
- void SW_NIBBLESET(Ptr byteptr, int nibblenum, char nibble); // set a nibble (0-F)
- char SW_NIBBLEGET(Ptr byteptr, int nibblenum); // get a nibble
-
-
- #define SW_BITSET(p,n) (p)[n >> 3] |= 0x80U >> (n & 7)
- #define SW_BITCLR(p,n) (p)[n >> 3] &= ~(0x80U >> (n & 7))
- #define SW_BITTST(p,n) ((p)[n >> 3] & (0x80U >> (n & 7))) != 0
-
- // (besides Perl this has to be the hairiest piece of code I've ever written :-) -- afb
-
- #define SW_NIBBLEGET(p,n) (((p)[n >> 1] & ~(0x0F << ((n & 1) << 2))) >> (((~n) & 1) << 2))
- //#define SW_NIBBLEGET(p,n) (n & 1) ? ((p[n>>1]>>4) & 0x0F) : ((p[n>>1] & 0x0F) // <-- unoptimized
-
- #define SW_NIBBLESET(p,n,c) (p)[n >> 1] = ( ((c) & 0x0F) << (((~n) & 1) << 2) ) | \
- ((p)[n >> 1] & (0x0F << ((n & 1) << 2)) )
- //#define SW_NIBBLESET(p,n,c) p[n>>1] = (n & 1) ? (((c & 0x0F) << 4) | (p[n>>1] & 0x0F) : \
- ((p[n>>1] & 0xF0) | (c & 0x0F)) // <-- unoptimized
-
- //------------------------------------------------------------------------------------------------
- // 24-bit memory mode macros, for the 68K
- ///-----------------------------------------------------------------------------------------------
-
- extern SInt8 gSWmmuMode;
-
- #if SW_68K
-
- #include <OSUtils.h>
-
- #define START_32_BIT_MODE \
- { \
- SInt8 mmuMode; \
- if (gSWmmuMode != true32b) \
- { \
- mmuMode = true32b; \
- SwapMMUMode(&mmuMode); \
- }
- #define END_32_BIT_MODE \
- if (gSWmmuMode != true32b) \
- { \
- SwapMMUMode(&mmuMode); \
- } \
- }
-
- #else
-
- #define START_32_BIT_MODE // we're always in 32-bit mode on PPC
- #define END_32_BIT_MODE
-
- #endif
-
- ///--------------------------------------------------------------------------------------
- // Rect macros
- ///--------------------------------------------------------------------------------------
-
- void BP_CLIP_RECT(RectPtr frameRectP, Rect srcRect, Rect dstRect);
- Boolean BP_EQUAL_RECT(Rect srcRect, Rect dstRect);
-
-
- // Clips dstRect and srcRect with frameRect.
- #define BP_CLIP_RECT(frameRectP, srcRect, dstRect) \
- /* clip off the top so we don't write into random memory */ \
- if (dstRect.top < frameRectP->top) \
- { \
- srcRect.top += frameRectP->top - dstRect.top; \
- dstRect.top = frameRectP->top; \
- } \
- /* clip off the bottom */ \
- if (dstRect.bottom > frameRectP->bottom) \
- { \
- srcRect.bottom -= dstRect.bottom - frameRectP->bottom; \
- dstRect.bottom = frameRectP->bottom; \
- } \
- /* Make sure height is valid */ \
- if (dstRect.bottom <= dstRect.top) \
- return; \
- /* clip off the left */ \
- if (dstRect.left < frameRectP->left) \
- { \
- srcRect.left += frameRectP->left - dstRect.left; \
- dstRect.left = frameRectP->left; \
- } \
- /* clip off the right */ \
- if (dstRect.right > frameRectP->right) \
- { \
- srcRect.right -= dstRect.right - frameRectP->right; \
- dstRect.right = frameRectP->right; \
- } \
- /* Make sure width is valid */ \
- if (dstRect.right <= dstRect.left) \
- return; \
-
- // check if two rects are equal
- #define BP_EQUAL_RECT( srcRect, dstRect ) \
- (srcRect.top == dstRect.top && \
- srcRect.bottom == dstRect.bottom && \
- srcRect.left == dstRect.left && \
- srcRect.right == dstRect.right )
-
-
- #endif // __BLITPIXIEINTERFACE__
-